<style lang="scss" scoped>
.container{
	width: 100vw;
	min-height: 100vh;
}
.item:nth-child(odd){
	background-color: #fff;
}
.item:nth-child(even){
	background-color: #e6e6e6;
}
.title{
	width: calc(100% - 240rpx);
}
.item{
	height: 74rpx;
}
button{
	height: 74rpx;
	width: 240rpx;
}
</style>
<template>
	<view class="pt-3 container">
<!-- 		<view class="item my-3 px-3 py-3" v-for="(val,index) in list" :key="val.id">
			<navigator :url="'../policy/details?id='+val.id" style="display: inline;">
				<text class="font-30" :class="{type:'title'}">{{val.title}}</text>
			</navigator>
			<button type="warn" plain class="float-right" @click="cancel_collect(index)" v-if="!!type" size="mini">取消收藏</button>
		</view> -->
		
		<uni-list :border="false" v-if="list.length">
			<uni-list-item    style="padding: 0;" :note="val.date" :to="'../policy/details?id='+val.id"  v-for="(val,index) in list" :key="val.id" :title="val.title"  :ellipsis="2">
				<template slot="footer" >
					<button v-if="!!type" type="warn" @click.stop="cancel_collect(index)" size="mini">取消收藏</button>
				</template>
			</uni-list-item>
		</uni-list>
		<view class="mt-5 pt-5" v-else>
			<image src="https://gov-tool.js-cx.cn/static/home/img/empty.png" mode="widthFix" class="empty mx-auto mt-5 d-block " style="width:40vw"></image>
			<text class="text-center d-block mt-5 color-999">暂无数据</text>
		</view>
	</view>
</template>
<script>
	import {getCollect,getHistory,setCollect } from "@api"
	export default {
		data() {
			return {
				type:1,
				list:[]
			}
		},
		methods:{
			cancel_collect(index){
				setCollect({
					openid:uni.getStorageSync('openid'),
					id:this.list[index].id,
					is:false
				})
				.then(res=>{
					if(res.data)
						this.list.splice(index,1)
				})
			}
		},
		onLoad({type}) {
			this.type=+type
			const func=+type?getCollect:getHistory
			func({openid:uni.getStorageSync('openid')})
			.then(res=>{
				this.list=res.list
			})
		}
	}
</script>